 //
 /// @file    anotherPoint.cc
 /// @author  lemon(haohb13@gmail.com)
 /// @date    2016-03-04 14:44:20
 ///
 
#include <iostream>
using std::cout;
using std::endl;


class Point;

class AnotherPoint
{
	friend class Point;
public:
	AnotherPoint(double dx = 1.0, double dy = 1.0)
	: _dx(dx)
	, _dy(dy)
	{
		cout << "AnotherPoint(double,double)" << endl;
	}

	friend std::ostream & operator<<(std::ostream & os, const AnotherPoint & rhs);
private:

	double _dx;
	double _dy;
};

std::ostream & operator<<(std::ostream & os, const AnotherPoint & rhs)
{
	os << "(" << rhs._dx << "," << rhs._dy << ")";
	return os;
}

class Point
{
	friend std::ostream & operator<<(std::ostream & os, const Point & rhs);
public:
	//explicit 
	Point(int ix = 0, int iy = 0)
	: _ix(ix)
	, _iy(iy)
	{
		//cout << "Point(int,int)" << endl;
	}
	//１.类型转换函数必须是成员函数
	//２.类型转换函数没有返回值类型，但是在
	//函数体内必须以传值的方式返回一个目标类型的变量
	//３.类型转换函数没有函数参数
	//４.不要轻易使用
	operator int ()
	{
		return _ix;
	}

	operator double()
	{
		return _ix * _iy;
	}

	operator AnotherPoint()
	{
		return AnotherPoint(_ix, _iy);
	}

private:
	int _ix;
	int _iy;
};

std::ostream & operator<<(std::ostream & os, const Point & rhs)
{
	os << "(" << rhs._ix << "," << rhs._iy << ")";
	return os;
}

int main(void)
{
	Point pt1(4, 5);
	cout << pt1 << endl;

	int x1 = pt1;
	cout << x1 << endl;

	double d = pt1;
	cout << d << endl;

	AnotherPoint ap = pt1;
	cout << ap << endl;

	return 0;
}
